package com.cloud.user_info.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.common.domain.Result;
import com.cloud.entity.SysUserAuth;
import com.cloud.entity.vo.AuthParam;
import com.cloud.user_info.mapper.SysUserAuthMapper;
import com.cloud.user_info.service.ISysUserAuthService;
import com.cloud.utils.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 账户第三方授权
 *
 * @author yzj
 */

@Service
public class SysUserAuthServiceImpl extends ServiceImpl<SysUserAuthMapper, SysUserAuth> implements ISysUserAuthService {

    @Resource
    private SysUserAuthMapper userAuthMapper;

    /**
     * 查询账户授权列表
     *
     * @param userAuth
     * @return
     */
    @Override
    public List<SysUserAuth> selectUserAuthList(SysUserAuth userAuth) {
        return userAuthMapper.selectUserAuthList(userAuth);
    }

    /**
     * 添加账户授权信息
     *
     * @param userAuth
     * @return
     */
    @Override
    public Result insertUserAuth(SysUserAuth userAuth) {
        if (StringUtils.isEmpty(userAuth.getAuthCode()) || StringUtils.isNull(userAuth.getAuthType())) {
            return Result.error("操作失败:认证编码,认证类型不能为空");
        }
        userAuthMapper.insert(userAuth);
        return Result.success("操作成功");
    }

    /**
     * 修改账户授权信息
     *
     * @param userAuth
     * @return
     */
    @Override
    public Result updateUserAuth(SysUserAuth userAuth) {
        if (StringUtils.isEmpty(userAuth.getAuthCode()) || StringUtils.isNull(userAuth.getAuthType())) {
            return Result.error("操作失败:认证编码,认证类型不能为空");
        }
        userAuthMapper.updateById(userAuth);
        return Result.success("操作成功");
    }

    /**
     * 删除授权信息
     *
     * @param authIds
     * @return
     */
    @Override
    public int deleteUserAuthById(List<Long> authIds) {
        return userAuthMapper.deleteUserAuthById(authIds);
    }

    /**
     * 根据UserId查询授权列表
     *
     * @param userId
     * @return
     */
    @Override
    public List<SysUserAuth> selectUserAuthById(Long userId) {
        return userAuthMapper.selectUserAuthById(userId);
    }

    /**
     * 根据类型获取授权ID列表
     *
     * @param authParam
     * @return
     */
    @Override
    public List<String> getUserAuthIds(AuthParam authParam) {
        return userAuthMapper.getUserAuthIds(authParam);
    }

}
